
<%@ include file="/WEB-INF/common/taglibs.jsp"%>
<script type="text/javascript"
	src="${ctx}/resources/js/datatable-query.js"></script>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="codec" uri="/WEB-INF/tld/codec.tld"%>




<div class="row-fluid">

	<div class="span12">
		<div class="box gradient">

			<div class="title">
				<h4>
					<span>Pay Pal Config </span> <span class="box-form right"> </span>

					<span class="box-form right payPalConfig_bar"><a href="#"
						class="btn btn-mini addPayPalConfig">Add Pay Pal Config</a></span>
				</h4>
				<a href="#" class="minimize"> </a>
			</div>
			<div class="content scrollable clearfix">
				<table
					class="table table-bordered table-vertical-centre payPalConfigTable">
					<thead>
						<tr>
							<th><a class="select_all"><span
									class="icomoon-icon-checkmark-2"></span></a></th>
							<th>Name</th>
							<th>Password</th>
							<th>Signature</th>
							<th>App Id</th>
							<th>Uat</th>

							<th>Action</th>
						</tr>
					</thead>
				</table>
			</div>

		</div>
	</div>
</div>




<script>
	$(document)
			.ready(
					function() {
						var del = {
							id : 'payPalConfigDel',
							text : 'Del',
							domain : "Pay Pal Config",
							operation : "Del",
							url : "${ctx}/admin/pay-pal-config/del/",
							selector : ".payPalConfig_bar",
							selects : $('.payPalConfigTable')

						};
						johnny.tableBtn(del);
						
						
						var apply = {
								id : 'payPalConfigApply',
								text : 'Apply',
								domain : "Pay Pal Config",
								operation : "Apply",
								url : "${ctx}/admin/pay-pal-config/apply/",
								selector : ".payPalConfig_bar",
								selects : $('.payPalConfigTable'),
								max  : 1

							};
							johnny.tableBtn(apply);
						
						

						$('.addPayPalConfig')
								.click(
										function() {
											$("#payPalConfigDiv")
													.find("div.modal-body")
													.find(
															"input,select,textarea,checkbox")
													.not(
															"[name=action],[type=hidden]")
													.not("[type=radio]")
													.each(
															function(step,
																	value) {
																if ($(this)
																		.is(
																				"select")) {
																	var d = $(
																			value)
																			.find(
																					"option:first")
																			.val();
																	$(this)
																			.val(
																					d);
																} else {
																	$(value)
																			.val(
																					"");
																}
																if (!$(value)
																		.hasClass(
																				"nostyle")) {
																	$(value)
																			.uniform();
																}
															});

											$(
													"#payPalConfigDiv input[name='action']")
													.val(
															"${ctx}/admin/pay-pal-config/create/");
											$("#payPalConfigDiv").modal('show');
										});

						$(document)
								.delegate(
										'.payPalConfigTable .icomoon-icon-pencil',
										'click',
										function(event) {

											var id = $(this).parent().attr(
													"dataid");
											$
													.ajax({
														url : "${ctx}/admin/pay-pal-config/"
																+ id + "/edit/",
														type : "GET",
														dataType : "json",
														success : function(data) {
															if (data
																	&& data.state
																	&& (data.state
																			.indexOf("ERROR") != -1)) {
																johnny
																		.error(data.message);
																return;
															} else {
																var entity = data.entity;

																$(
																		"#payPalConfigDiv")
																		.find(
																				"div.modal-body")
																		.find(
																				"input[name],select[name],textarea[name],checkbox[name]")
																		.not(
																				"[name=action],[type=hidden]")
																		.each(
																				function(
																						step,
																						value) {
																					var name = $(
																							value)
																							.attr(
																									"name");
																					if ($(
																							value)
																							.is(
																									':radio')) {
																						if (""
																								+ entity[name] === ""
																								+ $(
																										value)
																										.val()) {
																							$(
																									value)
																									.attr(
																											"checked",
																											"checked");
																						} else {
																							$(
																									value)
																									.removeAttr(
																											"checked");

																						}
																						
																						var css = $(":checkbox[fname="
																								+ name
																								+ "]");
																						if (css.length > 0) {
																							if ("true" === ""+ entity[name]) {
																								if (!css.attr("checked")) {
																									css.siblings("label")
																											.trigger('mousedown')
																											.trigger('mouseup')
																											.trigger('click').trigger("change");
																								}else{
																									
																									console.dir("no nothing")
																								}
																							} else {
																								if (css
																										.attr("checked")) {
																									css
																											.siblings(
																													"label")
																											.trigger(
																													'mousedown')
																											.trigger(
																													'mouseup')
																											.trigger(
																													'click').trigger("change");
																								}

																							}
																						}

																					} else {
																						if (entity[name]
																								|| entity[name] === 0) {
																							$(
																									value)
																									.val(
																											entity[name]);
																							if ($(
																									value)
																									.hasClass(
																											"nostyle")) {
																							} else {
																								$(
																										value)
																										.uniform();
																							}
																						} else if (name
																								.match(/Id$/)) {
																							var pro = name
																									.substring(
																											0,
																											name.length - 2);
																							if (entity[pro]
																									&& entity[pro].id) {
																								$(
																										value)
																										.val(
																												entity[pro].id);
																								if ($(
																										value)
																										.hasClass(
																												"nostyle")) {
																								} else {
																									$(
																											value)
																											.uniform();
																								}
																							}

																						} else {
																							$(
																									value)
																									.val(
																											"");
																						}
																					}

																				});

																var x = $(
																		"#payPalConfigDiv")
																		.find("div.modal-body")
																		.find('input[type="radio"]')
																		.not('.nostyle')
																		.uniform();
																														
																$(
																		"#payPalConfigDiv input[name='action']")
																		.val(
																				"${ctx}/admin/pay-pal-config/"
																						+ id
																						+ "/edit/");
																$(
																		"#payPalConfigDiv")
																		.modal(
																				'show');
															}
														}
													});

										});
						var recordColumn = [ '', 'name', 'password',
								'signature', 'appId', 'uat' ];

						$('.payPalConfigTable')
								.dataTable(
										{
											"bLengthChange" : true,
											"aoColumnDefs" : [ {
												'bSortable' : false,
												'aTargets' : [ 0, 3 ]
											} ],
											"sAjaxSource" : '${ctx}/admin/pay-pal-config/${entity.id}/',
											"createQueryData" : function(aoData) {
												return johnny.initQueryData(
														aoData, recordColumn);
											},
											"createResult" : function(json,
													echo) {
												var dataArray = new Array();
												for (var i = 0; i < json.result.length; i++) {
													var subArray = new Array();
													var value = johnny
															.getForSelect(json.result[i].id);
													subArray.push(value);
													subArray
															.push(json.result[i].name)
													subArray
															.push(json.result[i].password)
													subArray
															.push(json.result[i].signature)
													subArray
															.push(json.result[i].appId)
													subArray
															.push(json.result[i].uat)

													var conf = [ {
														link : 'javascript:void(1)',
														dataId : json.result[i].id,
														text : 'edit',
														css : 'icomoon-icon-pencil'
													}

													];
													subArray.push(johnny
															.getGridLink(conf));
													dataArray.push(subArray);
												}
												return {
													sEcho : echo,
													iTotalRecords : json.totalCount,
													iTotalDisplayRecords : json.totalCount,
													aaData : dataArray
												};
											}
										});

					});
</script>





<div id="payPalConfigDiv" class="modal hide fade"
	selector=".payPalConfigTable" style="display: none;">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal">
			<span class="icon12 minia-icon-close"></span>
		</button>
		<h3>Pay Pal Config</h3>
	</div>

	<div class="modal-body">
		<input type="hidden" name="action">
		<!--name -->
		<div class="form-row row-fluid">
			<div class="span12">
				<div class="row-fluid">
					<label class="form-label span3" for="name">Name :</label><input
						class="span9" id="name" name="name" type="text" value="" />
				</div>
			</div>
		</div>
		<!--password -->
		<div class="form-row row-fluid">
			<div class="span12">
				<div class="row-fluid">
					<label class="form-label span3" for="password">Password :</label><input
						class="span9" id="password" name="password" type="text" value="" />
				</div>
			</div>
		</div>
		<!--signature -->
		<div class="form-row row-fluid">
			<div class="span12">
				<div class="row-fluid">
					<label class="form-label span3" for="signature">Signature :</label><input
						class="span9" id="signature" name="signature" type="text" value="" />
				</div>
			</div>
		</div>
		<!--appId -->
		<div class="form-row row-fluid">
			<div class="span12">
				<div class="row-fluid">
					<label class="form-label span3" for="appId">App Id :</label><input
						class="span9" id="appId" name="appId" type="text" value="" />
				</div>
			</div>
		</div>
		<!--uat -->
		<div class="form-row row-fluid">
			<div class="span12">
				<div class="row-fluid">
					<label class="form-label span3" for="uat">Uat :</label>
					<div class="left marginT5 marginR10">
						<div class="normal-toggle-button">
							<input  fname="uat" type="checkbox" class="nostyle"> <input class="nostyle" type="radio"
								name="uat" id="uat1"  value="true" style="opacity: 0;"> <input
								class="nostyle" type="radio" name="uat" id="uat2" value="false"
								style="opacity: 0;">
						</div>
					</div>
				</div>
			</div>
		</div>


	</div>

	<div class="modal-footer">
		<a href="#" class="btn" data-dismiss="modal">Close</a> <a href="#"
			class="btn btn-primary modal-submit">Save changes</a>
	</div>

</div>


